<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author:HCZ <huangchengze@etrol.com>
// +-----------------------------------------------------------------------

namespace app\common\model;

use app\common\model\Base;
use app\basic\model\Enterprise;
/**
 * 模型基类
 */
class User extends Base{
	protected $createTime = 'registerDate';
	protected $updateTime = 'loginDate';
	protected $name='user';
	public $userPropertyList = [1=>'内部人员',2=>'园区企业',3=>'超级管理员'];
	
	/**
	 * 密码加密
	 * @param string $value
	 * @param array $data
	 * @return string
	 */
	public function setPasswordAttr($value,$data){
		return md5($value.$data['salt']);
	}
	
	
	public function getUserPropertyAttr($value,$data){
		if($data['userProperty']){
			return $this->userPropertyList[$data['userProperty']];
		}
		return null;
	}
	
	public function getUserPropertyIdAttr($value,$data){
		return $data['userProperty'];
	}
	
	public function roles()
	{

		return $this->belongsToMany('Role','roleaccess','roleId','userId');

	}
	public function enterprise(){

		return $this->hasOne(Enterprise::class,'id','enterpriseId');
	}
	
}